package com.dlwx.firefighting.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.dlwx.firefighting.R;
import com.dlwx.firefighting.utils.KeyBoardUtils;
import com.dlwx.firefighting.utils.ToastUtils;
import com.dlwx.firefighting.utils.glide.GlideImageLoader;
import com.dlwx.firefighting.widget.RoundCornerImageView;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 会员信息界面（用于转账时显示）
 */
public class MemberInfoActivity extends BaseActivity {

    @BindView(R.id.title_left_one_btn)
    ImageView titleLeftOneBtn;
    @BindView(R.id.tv_middle_title)
    TextView tvMiddleTitle;
    @BindView(R.id.tv_member_name)
    TextView tv_name;
    @BindView(R.id.tv_member_phone)
    TextView tv_phone;
    @BindView(R.id.edit_input_money)
    EditText edit_input;
    @BindView(R.id.button_transfer)
    TextView btn_transfer;
    @BindView(R.id.img_member_header)
    RoundCornerImageView img_header;

    private GlideImageLoader imageLoader = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_member_info);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        imageLoader = new GlideImageLoader(this);
        titleLeftOneBtn.setVisibility(View.VISIBLE);
        tvMiddleTitle.setText("转到对方余额");
        edit_input.addTextChangedListener(textWatcher);
        edit_input.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (MotionEvent.ACTION_DOWN == event.getAction()) {
                    edit_input.setCursorVisible(true);
                }
                return false;
            }
        });
    }



    @OnClick({R.id.title_left_one_btn, R.id.button_transfer})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_left_one_btn:
                finish();
                break;
            case R.id.button_transfer:
                KeyBoardUtils.closeKeybord(this);
                ToastUtils.toastForLong(this, "转账");
                break;
        }
    }

    TextWatcher textWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String money = edit_input.getText().toString();
            if (!TextUtils.isEmpty(money)) {
                btn_transfer.setBackgroundResource(R.drawable.bg_green_selector);
            } else {
                btn_transfer.setBackgroundResource(R.drawable.bg_grey);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    };


    @Override
    protected void onStart() {
        super.onStart();
        EventBus.getDefault().register(MemberInfoActivity.this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(MemberInfoActivity.this);
    }

    //---------------------------------------------------------
}
